package com.bbs.toutiao.mapper.clinet;

import com.bbs.toutiao.entity.UserEntity;
import com.bbs.toutiao.vo.client.AddNotificationVo;
import com.bbs.toutiao.vo.client.ArticleUserVo;
import com.bbs.toutiao.vo.client.GetCommentByUserIdVo;
import com.bbs.toutiao.vo.client.UserPhonePasswordVo;
import com.bbs.toutiao.vo.comment.CommentPageRequestVo;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * 描述: 前台用户mapper
 * 作者： zhangBin
 * 时间： 2023/10/8 11:06
 * 版本： 1.0
 */

@Mapper
public interface ClientUserMapper {


    //根据id和手机号更新用户密码
    @Update("update t_users set password = #{password} where phone = #{phone} and id = #{id}")
    int updatePasswordByPhoneId(UserPhonePasswordVo registerVo);

    //账号和密码登录或者手机号登录
    UserEntity selectUserByAccountAndPasswordOrPhone(UserPhonePasswordVo lrVo);

    //新增举报信息
    @Insert("insert into t_notifications(report_id,user_id,report_description,type,target_content) values (#{reportId},#{userId},#{reportDescription},#{type},#{targetContent})")
    int insertNotification(AddNotificationVo anVo);


    //查询指定用户分页的评论
    List<GetCommentByUserIdVo> getCommentByUserId(CommentPageRequestVo vo);


    //统计评论总数
    @Select("select count(*) from t_comments where user_id = #{userId}")
    long getCommentCountByUserId(CommentPageRequestVo vo);

    //id查询用户手机号
    @Select("select phone from t_users where phone = #{phone}")
    String getPhone(String phone);


    //根据id更新手机号
    @Update("update t_users set phone = #{phone} where id = #{id}")
    int updatePhoneById(UserPhonePasswordVo phoneVo);

    //查询指定id用户主页的信息
    @Select("select * from t_users where id = #{userId}")
    ArticleUserVo selectByUserId(int userId);

    //查询关注者
    @Select("select count(*) from t_follows where follower_id = #{userId}")
    long followsCount(int userId);

    //查询粉丝，被关注者
    @Select("select count(*) from t_follows where following_id = #{userId}")
    long followingCount(int userId);

    //查询关注者都是谁
    @Select("SELECT u.id as id  FROM t_follows f INNER JOIN t_users u  ON f.following_id = u.id WHERE f.follower_id = #{userId}")
    List<Integer> selectFollowsByUserId(int userId);

    //删除评论
    @Delete("delete from t_comments where id =#{id}")
    int deleteComment(Integer id);

    // 并且查询父评论修改父评论等级
    @Update("   UPDATE t_comments " +
            "   SET parent_id = #{parId}" +
            "   WHERE parent_id = #{id}")
    int updateParentId(Integer id,Integer parId);

    //查询用户收藏列表的文章id
    @Select("select article_id from t_favorites where user_id = #{userId}")
    List<Integer> selectFavoritesByUserId(int userId);
}
